<?php
namespace app\model;

class ActivityUser extends  \think\Model{
    public $table="activity_user";

    /**添加一条用户参加招聘活动记录
     * @param $activity_id
     * @param $user_id
     * @return int|string
     */
    function add_user_join_activity_log($activity_id,$user_id){
        return $this->insert(['activity_id'=>$activity_id,'user_id'=>$user_id,'created_at'=>cur_time()]);
    }

    /**
     * 用户是否参加 了指定的招聘活动
     * @param $activity_id
     * @param $user_id
     * @return bool
     */
    function if_join_activity($activity_id,$user_id){
        $o=$this->where(['activity_id'=>$activity_id,'user_id'=>$user_id])->column('id');
        if($o[0]==true){
            return true;
        }else{
            return false;
        }
    }

    /**
     * 根据活动ID，返回已经报名参加的招聘活动的用户信息
     * @param $activity_id
     */
    function get_join_user_by_activity_id($activity_id){
        $o=$this->where(['activity_id'=>$activity_id])->select();
        $arrs=object2array($o);
        $UserResume=new UserResume();
        $User=new User();
        foreach($arrs as $k=>$v){
            $arrs[$k]['user_info']=$UserResume->get_info($v['user_id']);
            $arrs[$k]['user_exp_info']=$User->get_exp($v['user_id']);
        }
        return $arrs;
    }

    /**
     * 返回已经参加的指定的招聘活动的用户数
     * @param $activity_id
     * @return int|string
     */
    function get_ac_join_user($activity_id){
        return $this->where(['activity_id'=>$activity_id])->count();
    }

}